<script lang="ts" setup>
import { injectState } from "../state";
import { SAFETY_TYPE_OPTIONS } from "@/config/enum-options";

defineOptions({ name: "Filters" });

const {
	filter,
	page: { isLoading },
} = injectState()!;

const initial = { ...toRaw(filter.value) };
const data = ref({ ...initial });

const search = () => {
	filter.value = { ...toRaw(data.value) };
};

const reset = () => {
	data.value = { ...initial };
};
</script>

<template>
	<el-form class="filter-form" inline :model="data" :disabled="isLoading">
		<el-form-item label="所属类型">
			<el-select-v2
				:options="[...SAFETY_TYPE_OPTIONS]"
				v-model="data.type"
				clearable
				w="240px!"
			/>
		</el-form-item>
		<el-form-item label="评估时间" prop="评估时间">
			<el-date-picker
				v-model="data.evaluateTimeStart"
				clearable
				type="date"
				class="w-240px!"
				placeholder="开始日期"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>
		<el-form-item label="—" prop="—">
			<el-date-picker
				v-model="data.evaluateTimeEnd"
				clearable
				type="date"
				class="w-240px!"
				placeholder="结束日期"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>
		<el-form-item>
			<el-divider direction="vertical" h="32px!" m="r-22px!" />
			<el-button type="primary" :loading="isLoading" @click="search">
				<template #icon>
					<el-icon class="i-custom:search" />
				</template>
				查询
			</el-button>
			<el-button @click="reset">
				<template #icon>
					<el-icon class="i-custom:reset" />
				</template>
				重置
			</el-button>
		</el-form-item>
	</el-form>
</template>
